package async;

import java.util.concurrent.locks.LockSupport;

/**
 * @author fei.fang
 * @date 2021/8/27
 **/
public class LockSupportTest {

    private static Object u = new Object();


    public static class LockSupRun implements Runnable{

        @Override
        public void run() {
//            synchronized (u){
                System.out.println("in " + Thread.currentThread().getName());

                LockSupport.park();

                if (Thread.interrupted()) {
                    System.out.println(Thread.currentThread().getName() + "中断了");
                }
//            }
            System.out.println(Thread.currentThread().getName() + "执行结束了");
        }
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(new LockSupRun());
        Thread t2 = new Thread(new LockSupRun());

        try {
            Thread.sleep(1000);
            t1.start();
            Thread.sleep(1000);
            t2.start();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        LockSupport.unpark(t1);
//        LockSupport.unpark(t2);
        t2.interrupt();
    }

}
